package 领扣算法.力扣计划.算法基础.被围绕的区域;

public class Main {
    public void solve(char[][] board) {
       char[][] data=new char[board.length+2][board[0].length+2];
        for (int i = 0; i < data.length; i++) {
            for (int j = 0; j < data[0].length; j++) {
                if (i==0||j==0||i==data.length-1||j==data[0].length-1)
                    data[i][j]='O';
                else
                    data[i][j]='X';
            }
        }
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[0].length; j++) {
               if (board[i][j]=='O'&&(data[i][j+1]=='O'||data[i+2][j+1]=='O'||data[i+1][j]=='O'||data[i+1][j+2]=='O')){
                 data[i+1][j+1]='O';
               }
            }
        }
        boolean flag=true;
        while (flag){
            flag=false;
            for (int i = board.length-1; i >=0; i--) {
                for (int j = board[0].length-1; j >0; j--) {
                    if (data[i+1][j+1]=='X'&&board[i][j]=='O'&&(data[i][j+1]=='O'||data[i+2][j+1]=='O'||data[i+1][j]=='O'||data[i+1][j+2]=='O')){
                        data[i+1][j+1]='O';
                        flag=true;
                    }
                }
            }
        }

        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[0].length; j++) {
                board[i][j]=data[i+1][j+1];
            }
        }
    }


}
